package com.rht.gulimallmember.controller;

import java.util.Arrays;
import java.util.Map;

import com.rht.gulimallmember.service.feignservice.CouponFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rht.gulimallmember.entity.MemberEntity;
import com.rht.gulimallmember.service.MemberService;
import com.rht.common.utils.PageUtils;
import com.rht.common.utils.R;




/**
 * 会员
 *
 * @author rht
 * @email rht@qq.com
 * @date 2024-11-07 13:57:31
 */

@RestController
@RequestMapping("gulimallmember/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 列表
     */
    @Autowired
    private CouponFeignService couponFeignService;

    //根据id查询指定会员，并查询所有优惠卷
    @Operation(summary = "根据id查询指定会员，并查询所有优惠卷")
    @RequestMapping("/getMemberByIdAndCoupon")
    public R getMemberByIdAndCoupon(Integer id){
        System.out.println("-----getMemberByIdAndCoupon----------");
        System.out.println("id:"+id);
        //根据id查询指定的会员
        MemberEntity member=memberService.getById(id);
        //查询所有优惠卷
        R membercoupon=couponFeignService.getAll();
        //返回结果
        return R.ok().put("member",member).put("coupons",membercoupon.get("list"));
    }
        @Operation(summary ="处理查询全部,分页查询的请求")
    @RequestMapping("/list")
      public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */

    @Operation(summary ="信息")
    @RequestMapping("/info/{id}")
      public R info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @Operation(summary ="保存")
    @RequestMapping("/save")
     public R save(@RequestBody MemberEntity member){
		memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @Operation(summary ="修改")
    @RequestMapping("/update")
     public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @Operation(summary ="删除")
    @RequestMapping("/delete")
      public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
